Telegram Group & Telegram Channel
💬 DFS vs BFS на Python

Если хотите разобраться, как алгоритмы поиска в глубину и поиска в ширину работают на практике, то вот минимальный пример, который покажет разницу.

graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}

def dfs(node, visited=set()):
if node in visited: return
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(neighbor, visited)

def bfs(start):
queue = [start]
visited = set()
while queue:
node = queue.pop(0)
if node in visited: continue
print(node)
visited.add(node)
queue += graph[node]


➡️ Что делает

— dfs проходит глубоко: A → B → D → E → C → F
— bfs — по уровням: A → B → C → D → E → F
— Обе функции показывают порядок обхода графа

🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/proglib_academy/2787
Create:
Last Update:

💬 DFS vs BFS на Python

Если хотите разобраться, как алгоритмы поиска в глубину и поиска в ширину работают на практике, то вот минимальный пример, который покажет разницу.

graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F'],
'D': [], 'E': [], 'F': []
}

def dfs(node, visited=set()):
if node in visited: return
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(neighbor, visited)

def bfs(start):
queue = [start]
visited = set()
while queue:
node = queue.pop(0)
if node in visited: continue
print(node)
visited.add(node)
queue += graph[node]


➡️ Что делает

— dfs проходит глубоко: A → B → D → E → C → F
— bfs — по уровням: A → B → C → D → E → F
— Обе функции показывают порядок обхода графа

🔵 Чтобы знать об алгоритмах все, забирайте наш курс «Алгоритмы и структуры данных»

Proglib Academy #буст

BY Proglib.academy | IT-курсы




Share with your friend now:
tg-me.com/proglib_academy/2787

View MORE
Open in Telegram


Proglib academy | IT курсы Telegram | DID YOU KNOW?

Date: |

How Does Bitcoin Work?

Bitcoin is built on a distributed digital record called a blockchain. As the name implies, blockchain is a linked body of data, made up of units called blocks that contain information about each and every transaction, including date and time, total value, buyer and seller, and a unique identifying code for each exchange. Entries are strung together in chronological order, creating a digital chain of blocks. “Once a block is added to the blockchain, it becomes accessible to anyone who wishes to view it, acting as a public ledger of cryptocurrency transactions,” says Stacey Harris, consultant for Pelicoin, a network of cryptocurrency ATMs. Blockchain is decentralized, which means it’s not controlled by any one organization. “It’s like a Google Doc that anyone can work on,” says Buchi Okoro, CEO and co-founder of African cryptocurrency exchange Quidax. “Nobody owns it, but anyone who has a link can contribute to it. And as different people update it, your copy also gets updated.”

To pay the bills, Mr. Durov is issuing investors $1 billion to $1.5 billion of company debt, with the promise of discounted equity if the company eventually goes public, the people briefed on the plans said. He has also announced plans to start selling ads in public Telegram channels as soon as later this year, as well as offering other premium services for businesses and users.

Proglib academy | IT курсы from sg


Telegram Proglib.academy | IT-курсы
FROM USA